﻿using System.Data.Entity.ModelConfiguration;

namespace Delphi.Mimir.Data.Entities.Final.Mappings {
    public class ManagedProductPositionMap : EntityTypeConfiguration<ManagedProductPosition> {
        public ManagedProductPositionMap() {
            /******************************************************************
            /* Table
            /*****************************************************************/
            ToTable("fin.pfm_managed_prod_positions");

            /******************************************************************
            /* Primary Key
            /*****************************************************************/
            HasKey(a => a.ManagedProductPositionId);

            /******************************************************************
            /* Index
            /*****************************************************************/
            // None

            /******************************************************************
            /* Relationships
            /*****************************************************************/
            // tbd
            HasRequired<Symbol>(a => a.Symbol)
                .WithMany()
                .HasForeignKey(a => a.SymbolId)
                .WillCascadeOnDelete(false);

            HasRequired<ManagedProduct>(a => a.ManagedProduct)
                .WithMany()
                .HasForeignKey(a => a.ManagedProductId)
                .WillCascadeOnDelete(false);

            /*
            HasMany<OrderExecution>(a => a.OrderExecutions)
                .WithRequired()
                .HasForeignKey(a => a.OrderExecutionId);
            */

            /******************************************************************
            /* Properties
            /*****************************************************************/
            Property(a => a.ManagedProductPositionId)
                .IsRequired()
                .HasColumnName("mpp_id");

            Property(a => a.ManagedProductId)
                .IsRequired()
                .HasColumnName("mpp_mpd_id");

            Property(a => a.SymbolId)
                .IsRequired()
                .HasColumnName("mpp_sym_id");

            Property(a => a.Quantity)
                .IsRequired()
                .HasColumnName("mpp_quantity");

            Property(a => a.ValidFromDate)
                .IsRequired()
                .HasColumnName("mpp_valid_frm_dt");

            Property(a => a.ValidUntilDate)
                .IsRequired()
                .HasColumnName("mpp_valid_til_dt");

            Ignore(a => a.Orders);

            Ignore(a => a.OrderExecutions);
        }
    }
}
